package main

import (
	"math"
	"sort"
)

func subSort2(array []int) []int {
	newArr := make([]int, len(array))
	copy(newArr, array)
	sort.Slice(newArr, func(i, j int) bool {
		if newArr[i] < newArr[j] {
			return true
		}
		return false
	})

	res := make([]int, 2)
	res[0] = -1
	res[1] = -1
	l, r := 0, 0

	for l < len(array) {
		if array[l] != newArr[l] {
			res[0] = l
			l++
			break
		}
	}

	for r >= 0 {
		if array[r] != newArr[r] {
			res[1] = r
			r--
			break
		}
	}

	return res
}

func subSort(array []int) []int {
	res := make([]int, 2)
	res[0] = -1
	res[1] = -1
	min := math.MinInt
	max := math.MaxInt
	for i := 0; i < len(array); i++ {
		if array[i] < max {
			res[0] = i
		} else {
			max = array[i]
		}

		if array[len(array)-i-1] > min {
			res[1] = len(array) - i - 1
		} else {
			min = array[len(array)-i-1]
		}
	}

	return res
}
